<html>

<head>

<title>Calculator</title>
<script type = "text/javascript">
var a;
var b;
a="";
var sign;
function calc(val){
a=a+val;
document.getElementById('txt').value=a;
};
function calcc(val){
if (val == 'c'){
a='';
document.getElementById('txt').value="";
}};
function calcsign(x){
b=a;
a='';
sign=x;
document.getElementById('txt').value=x;
};
function calce(){
switch (sign){
case "+":
document.getElementById('txt').value=a+b;
break;
case '-':
document.getElementById('txt').value=b-a;
break;
case 'x':
document.getElementById('txt').value=a*b
break;
case '/':
document.getElementById('txt').value=b/a;
break;
};};
</script>
</head>
<body> 
<table border="1" width="4%">
<th colspan="4" ><input type="text" id="txt" /></th>
<tr>
<td><input type="button" name="1" value =" 1 " onclick="calc(1)" /></td>
<td><input type="button" name="2" value =" 2 "id="2" onclick="calc(2)" /></td>
<td><input type="button" name="3" value =" 3 " id="3" onclick="calc(3)" /></td>
<td><input type="button" name="p" value =" + " id="p" onclick="calcsign('+')" /></td>
</tr>
<tr>
<td><input type="button" name="4" value =" 4 " id="4" onclick="calc(4)" /></td>
<td><input type="button" name="5" value =" 5 "  id="5" onclick="calc(5)" /></td>
<td><input type="button" name="6" value =" 6 " id="6" onclick="calc(6)" /></td>
<td><input type="button" name="m" value =" - " id="d" onclick="calcsign('-')" /></td>
</tr>
<tr>
<td><input type="button" name="7" value =" 7 " id="7" onclick="calc(7)" /></td>
<td><input type="button" name="8" value =" 8 " id="8" onclick="calc(8)" /></td>
<td><input type="button" name="9" value =" 9 "  id="9" onclick="calc(9)" /></td>
<td><input type="button" name="x" value =" x " id="x" onclick="calcsign('x')" /></td>
</tr>
<tr>
<td><input type="button" name="c" value =" c " id="c" onclick="calcc('c')" /></td>
<td><input type="button" name="0" value =" 0 " id="0" onclick="calc(0)" /></td>
<td><input type="button" name="e" value =" = " id="e" onclick="calce()" /></td>
<td><input type="button" name="d" value =" / " id="d" onclick="calcsign('/')" /></td>
</tr>
</table>
</form>
</body>

</html>
